package com.zym.test;

import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
import cloud.tianai.captcha.generator.common.model.dto.ImageCaptchaInfo;
import cloud.tianai.captcha.generator.impl.MultiImageCaptchaGenerator;
import cloud.tianai.captcha.resource.ImageCaptchaResourceManager;
import cloud.tianai.captcha.resource.impl.DefaultImageCaptchaResourceManager;
import cloud.tianai.captcha.validator.ImageCaptchaValidator;
import cloud.tianai.captcha.validator.impl.BasicCaptchaTrackValidator;
import com.zym.entity.Emp;
import com.zym.entity.User;
import com.zym.utils.EasyExcel.ExcelUtil;
import com.zym.utils.EasyExcel.ExcelValidateHelper;
import com.zym.vo.EmpVo;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class demo {
    public static void main(String[] args) throws Exception {
//        List<Emp> data = data();
//
//        Workbook sheets = new SXSSFWorkbook();
//        Sheet sheet= sheets.createSheet("第一个");
//
//        for (int i = 0; i < data.size(); i++) {
//             Row row = sheet.createRow(i);
//            Date hiredate = data.get(i).getHiredate();
//            SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
//            String format = simpleDateFormat.format(hiredate);
//            row.createCell(0).setCellValue(data.get(i).getEmpno());
//               row.createCell(1).setCellValue(data.get(i).getEname());
//               row.createCell(2).setCellValue(format);
//               row.createCell(3).setCellValue(data.get(i).getJob());
//               row.createCell(4).setCellValue(data.get(i).getDeptno());
//               row.createCell(5).setCellValue(  String.valueOf(data.get(i).getSal()));
//               row.createCell(6).setCellValue(data.get(i).getMgr());
//               row.createCell(7).setCellValue(  String.valueOf(data.get(i).getComm()));
//        }
//
//        FileOutputStream fileOutputStream = new FileOutputStream("test.xlsx");
//        sheets.write(fileOutputStream);
//        fileOutputStream.close();
//        sheets.close();
      //  readData("test.xlsx");
//        EmpVo empVo = new EmpVo().setEmpno(12).setDeptno("15215425648").setComm(new BigDecimal(19)).setEname("zym").setHiredate(new Date())
//                .setMgr(1).setJob("");
//        String s = ExcelValidateHelper.validateEntity(empVo);
//        System.out.println(s);

        EmpVo empVo = new EmpVo();
        empVo.setErrorMsg("q2e");
        empVo.setEmpno(12);
        empVo.setMgr(33);
        empVo.setHiredate(new Date());
        empVo.setDeptno("122");
        empVo.setEname("qwr");
        empVo.setJob("q3e");
        EmpVo empVo1 = new EmpVo();
        empVo1.setErrorMsg("q2e");
        empVo1.setEmpno(12);
        empVo1.setMgr(33);
        empVo1.setHiredate(new Date());
        empVo1.setDeptno("122");
        empVo1.setEname("qwr");
        empVo1.setJob("q3e");
        List<EmpVo> empVos = Arrays.asList(empVo, empVo1);

        ExcelUtil.writeExcel(null,"12",EmpVo.class,empVos);
    }
    public static List<Emp> readData(String path){
        List<Emp> empList=new ArrayList<>();
        try {
            FileInputStream fileInputStream = new FileInputStream(path);
            Workbook workbook = new XSSFWorkbook(fileInputStream);
            int numberOfSheets = workbook.getNumberOfSheets();


            for (int i = 0; i < numberOfSheets; i++) {
                Emp emp = new Emp();
                Sheet sheetAt = workbook.getSheetAt(i);
                //得到多少列数据
                int physicalNumberOfCells = sheetAt.getRow(0).getPhysicalNumberOfCells();
                //得到多少行数据
                int physicalNumberOfRows = sheetAt.getPhysicalNumberOfRows();
                System.out.println(numberOfSheets+":"+physicalNumberOfCells+":"+physicalNumberOfRows);

                Row row = sheetAt.getRow(i+1);
                for (int j = 0; j < physicalNumberOfCells; j++) {

//                    emp.setEmpno((int) row.getCell(j).getNumericCellValue())
//                            .setEname(row.getCell(j).getStringCellValue())
//                            .setHiredate(row.getCell(j).getDateCellValue())
//                            .setJob(row.getCell(j).getStringCellValue())
//                            .setDeptno(Integer.valueOf(row.getCell(j).getStringCellValue()));
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
return null;
    }
    public static List<Emp> data(){
        List<Emp> empList=new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            Emp emp = new Emp();
            emp.setEmpno(i);
            emp.setComm(new BigDecimal("12.2"));
            emp.setDeptno(i+100);
            emp.setEname("zym"+i);
            emp.setHiredate(new Date());
            emp.setJob("asasa");
            emp.setMgr(1);
            emp.setSal(new BigDecimal("123"));
            empList.add(emp);
        }
        return empList;
    }
}
